<template>
  <div class="app-container home">
    <div class="welcome-section">
      <h2>{{ $t("common.welcome") }}, {{ nickName }}!</h2>
      <p>{{ $t("common.systemName") }} v{{ version }}</p>
    </div>
    <el-row :gutter="20" class="quick-actions">
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="action-card" @click.native="goTo('employee')">
          <div class="icon"><i class="el-icon-user"></i></div>
          <div class="title">{{ $t("home.employeeManage") }}</div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="action-card" @click.native="goTo('attendance')">
          <div class="icon"><i class="el-icon-date"></i></div>
          <div class="title">{{ $t("home.attendance") }}</div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="action-card" @click.native="goTo('salary')">
          <div class="icon"><i class="el-icon-money"></i></div>
          <div class="title">{{ $t("home.salary") }}</div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="action-card" @click.native="goTo('notice')">
          <div class="icon"><i class="el-icon-message"></i></div>
          <div class="title">{{ $t("home.notice") }}</div>
        </el-card>
      </el-col>
    </el-row>
    <el-card class="notice-board" style="margin-top: 32px">
      <div slot="header">
        <span>{{ $t("home.announcement") }}</span>
      </div>
      <ul>
        <li v-for="(item, idx) in announcements" :key="idx">
          <i class="el-icon-info"></i>
          {{ item }}
        </li>
      </ul>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "Index",
  data() {
    return {
      version: "3.8.9",
      announcements: [
        this.$t("home.announcement1"),
        this.$t("home.announcement2"),
        this.$t("home.announcement3"),
      ],
    };
  },
  methods: {
    goTo(module) {
      // 跳转到对应模块页面
      switch (module) {
        case "employee":
          this.$router.push("/employee");
          break;
        case "attendance":
          this.$router.push("/attendance");
          break;
        case "salary":
          this.$router.push("/salary");
          break;
        case "notice":
          this.$router.push("/notice");
          break;
      }
    },
  },
  computed: {
    ...mapGetters(["nickName"]),
  },
};
</script>

<style scoped lang="scss">
.home {
  .welcome-section {
    margin-bottom: 32px;
    h2 {
      margin: 0 0 8px 0;
      font-weight: 600;
    }
    p {
      color: #888;
      margin: 0;
    }
  }
  .quick-actions {
    margin-bottom: 32px;
    .action-card {
      text-align: center;
      cursor: pointer;
      transition: box-shadow 0.2s;
      .icon {
        font-size: 36px;
        color: #409eff;
        margin-bottom: 8px;
      }
      .title {
        font-size: 16px;
        font-weight: 500;
      }
      &:hover {
        box-shadow: 0 2px 12px #409eff22;
      }
    }
  }
  .notice-board {
    ul {
      padding-left: 20px;
      margin: 0;
      li {
        margin-bottom: 8px;
        color: #666;
        font-size: 14px;
        i {
          color: #409eff;
          margin-right: 6px;
        }
      }
    }
  }
}
</style>
